class RateController {
    def scaffold = Rate

    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max)params.max = 10
        [ rateList: Rate.list( params ) ]
    }

    def show = {
        [ rate : Rate.get( params.id ) ]
    }

    def delete = {
        def rate = Rate.get( params.id )
        if(rate) {
            rate.delete()
            flash.message = "Rate ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Rate not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def rate = Rate.get( params.id )

        if(!rate) {
                flash.message = "Rate not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ rate : rate ]
        }
    }

    def update = {
        def rate = Rate.get( params.id )
        if(rate) {
             rate.properties = params
            if(rate.save()) {
                flash.message = "Rate ${params.id} updated."
                redirect(action:show,id:rate.id)
            }
            else {
                render(view:'edit',model:[rate:rate])
            }
        }
        else {
            flash.message = "Rate not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
      def rate = new Rate()
      rate.properties = params
      return ['rate':rate]
    }

    def save = {
        def rate = new Rate()
        rate.properties = params
        if(rate.save()) {
            flash.message = "Rate ${rate.id} created."
            redirect(action:show,id:rate.id)
        }
        else {
            render(view:'create',model:[rate:rate])
        }
    }

}